﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mystery.SharePoint
{
	/// <summary>
	/// Extensions to the IEnumerable interface
	/// </summary>
	public static class IEnumerableExtensions
	{
		/// <summary>
		/// Creates a string with all the elements contained
		/// </summary>
		/// <param name="enumerable"></param>
		/// <param name="seperator">The seperator used to distinguish each element</param>
		/// <returns>A string with all the elements seperated using the provided string</returns>
		public static string CreateSeperatedString(this IEnumerable enumerable, string seperator)
		{
			if (enumerable == null) throw new ArgumentNullException("enumerable");
			if(string.IsNullOrEmpty(seperator) == true) throw new ArgumentNullException("seperator");

			bool first = true;
			StringBuilder sb = new StringBuilder();

			foreach (var item in enumerable)
			{
				if (first == true)
				{
					sb.Append(item.ToString());
					first = false;
				}
				else
				{
					sb.AppendFormat(";{0}", item);
				}
			}
			return sb.ToString();
		}
	}
}
